home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / fido / RFS275.lha / rexx / RFSfileLIST.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-11  |  9KB  |  252 lines

  1. /**/
  2. v="$VER: RFSFileList  Rexx FileList Creator Williamson 54.11"
  3. debug=0
  4. system="Amiga ECS"              /* Your system name and address here */
  5. listnote="Available files, updated "date()" MAGIC:FILES"
  6. default="  Sorry, there is no description for this area"cr||cr
  7. /*          ^^ spaces required! */
  8. /*  You must create these files */
  9. bbslist="CFG:Browse.CFG"    /* filearea config  */
  10. htext="CFG:ABOUT.txt"  /* System header */
  11. areatext='area.text'            /* area description */
  12. /* output files - edit names to suit */
  13. allfileslist="MAIL:FILELISTS/01670104.LST"    /* Output File List */
  14. allfilesarc ="MAIL:FILELISTS/01670104.LHA"    /* Archived Normal List */
  15. filesbbs ="files.bbs"           /* area desc and files */
  16. /* WB2 List Lformat parameters  */
  17. EXCLUDE='~(area.text|files.bbs|LZTEMP.#?|.info)'    /* LIST exclusion parameters    */
  18. LFMT_LIST='"%-20N%7L %-9D %C"'  /* all files list   */
  19. LFMT_BBS='"%-30N %C"'           /* areas.bbs        */
  20. FLLEN=77                        /* list line length  */
  21. MARGINALL=39                    /* margin for LFMT_LIST  - wraptofile prepends a space  */
  22. /* used internally */
  23. fileslist="T:ALST-"Pragma('ID')      /* temporary all file */
  24. tmpbbs="T:MLST-"Pragma('ID')         /* temporary area list */
  25. script="RFSfileList";ver="v"||right(v,5);fmvers=script ver
  26. cr='0a'x;lf='0a'x
  27. CSI='9b'x;AOFF=CSI||'0m';BOLD=CSI||'1m';ULINE=CSI||'4m';ITALICS=CSI||'3;40m'
  28.  
  29. if ~show("L", "rexxsupport.library") then
  30.     if ~addlib("rexxsupport.library", 0, -30, 0) then do
  31.             say "Couldn't access support.library !"
  32.             exit 20
  33.     end
  34.  
  35. options results
  36. options failat 20
  37. signal on halt
  38. signal on ioerr
  39. signal on break_c
  40. signal on break_d
  41.  
  42. call close('STDOUT')
  43. call open('STDOUT',"CON:0/10/640/100/"script ver"/CLOSE",'w')
  44. call close('STDIN')
  45. call open('STDIN','*','R')
  46. call Pragma("P",-1)
  47.  
  48. /* Start Area Processing */
  49. if ~open('dlst',bbslist, 'R') then do
  50.     call writeln(STDOUT, "Couldn't open fileareas list" bbslist)
  51.     signal cleanup
  52. end
  53. if show('p',"ROOFLOG") then address 'ROOFLOG' 'logline' left(time(),5) script': Updating FILE Listing'
  54. call writeln(STDOUT, lf||ITALICS||" "fmvers||lf||" by Robert Williamson 1:167/104.0@fidonet"||AOFF)
  55. /* Start Area Processing */
  56. call writeln(STDOUT, 'Reading file area configuration')
  57. area=1
  58. do while ~eof('dlst')
  59.     call writech(STDOUT,'.')
  60.     blstln=readln('dlst')
  61.     if blstln="" then iterate
  62.     parse var blstln Number.area '"' Path.area '"' '"' Name.area '"'
  63.     if upper(strip(dequote(Path.area)))="NULL:" then iterate
  64.     area=area+1
  65. end /*eof*/
  66. call close('dlst')
  67.  
  68. areas=area-1
  69. call writeln(STDOUT,"")
  70. call writeln(STDOUT,'Found 'areas' file areas')
  71.  
  72. /* open all file listing, put title, date and system header */
  73. call writeln(STDOUT,ULINE||"Generating All Files Listing for "system||AOFF||cr)
  74. if debug then call writeln(STDOUT,'Adding date/version header to 'fileslist)
  75. open('tbl', fileslist, 'W')
  76.   call writech('tbl',"   "fmvers" by Robert Williamson 1:167/104.0@fidonet"cr)
  77.   call writech('tbl',"   FileListing for" system  delstr(space(date(), 1, "-"), 8, 2) time()||cr ||cr)
  78. close('tbl')
  79.  
  80. if ~exists('htext') then do
  81.     if debug then call writeln(STDOUT,'Adding headerfile' htext 'to 'fileslist)
  82.     com='Type >> "'fileslist'" "'htext'"'
  83.     address COMMAND com
  84. end
  85.  
  86. do area=1 to areas
  87.     areadir=addslash(dequote(Path.area))
  88.     if debug then call writeln(STDOUT,'Updating area' Name.area)
  89.     call listandsort(areadir,areadir||filesbbs,LFMT_BBS)
  90.     call addareatext(areadir,areadir||filesbbs,areatext,areadir||filesbbs,'prepend')
  91.     call addheaders()    
  92.     call listandsort(areadir,tmpbbs,LFMT_LIST)
  93.     if ~open('ifn',tmpbbs,'R') then do
  94.         call writeln(STDOUT,'wraptofile:Cannot open 'tmpbbs)
  95.         signal cleanup
  96.     end
  97.     if ~open('ofn',fileslist,'A') then do
  98.         call writeln(STDOUT,'wraptofile:Cannot append Area List to 'fileslist)
  99.         signal cleanup
  100.     end
  101.     do while ~eof('ifn')
  102.         line=readln('ifn')
  103.         if left(line,1) ~= " " then call writech('ofn',' 'wrap_line(line,FLLEN,MARGINALL)) 
  104.         else call writech('ofn',line||cr)
  105.     end /*eof */
  106.     call close('ifn')
  107.     call close('ofn')
  108. end
  109. address COMMAND 'Copy' fileslist allfileslist
  110. address COMMAND 'FileNote "'allfileslist'" "'listnote'"'
  111. call writeln(STDOUT,'Archiving 'allfileslist' as 'allfilesarc)
  112. address COMMAND 'lha -2 u "'allfilesarc'" "'allfileslist'"'
  113. address COMMAND 'FileNote "'allfilesarc'" "'listnote'"'
  114. call writeln(STDOUT,' File Listing completed')
  115. cleanup:
  116. call delete(fileslist)
  117. call delete(tmpbbs)
  118. exit 0
  119.    
  120. listandsort:
  121. /* list <tdir> with <lfmt> and sort to <tfile> */
  122. tdir=arg(1);tfile=arg(2);lfmt=arg(3)
  123. las='PIPE LIST 'tdir||exclude' FILES NOHEAD LFORMAT 'lfmt' | SORT In: 'tfile
  124. address command las
  125. return 0
  126.  
  127. /* prepend area.text to files.bbs                               */
  128. /*    addareatext(areadir,files.bbs,area.text,output)           */
  129. /*    addareatext(areadir,files.bbs,area.text,output,where)     */
  130. /* where= append or prepend(DEFAULT)                            */
  131. /*  example:                                                    */
  132. /*    call addareatext(Path.area,availlist,areatext,availlist)  */
  133. addareatext:
  134. descfile=addslash(dequote(arg(1)))||arg(3)
  135. inlist=arg(2);tolist=arg(4);where=arg(5)
  136. if ~exists(inlist) then do
  137.     call writeln(STDOUT,'addareatext: cannot find 'inlist)
  138.     return 20
  139. end
  140.  
  141. if ~exists(descfile) then do
  142.     call writeln(STDOUT,'addareatext: cannot find 'descfile' using 'default)
  143.     if where='append' then do
  144.         call open('ds',descfile,'A')
  145.         call writech('ds',default)
  146.     end;else do
  147.         call open('ds',descfile,'W')
  148.         call writech('ds',default)
  149.     end
  150.     call close('ds')  
  151. end
  152. if where='append' then call join(inlist,descfile,tolist)
  153.     else call join(descfile,inlist,tolist)
  154. return 0
  155.  
  156. wrap_line:
  157. text=arg(1)
  158. right_edge=arg(2)  /* line length */
  159. left_edge=arg(3)  /*   margin    */
  160. new_text=''
  161. do while length(text) > 0
  162.     broken_word=0
  163.     if length(text) < right_edge then do
  164.         new_text=new_text || text || '0a'x
  165.         text=''
  166.     end;else do
  167.         temp_text=strip(text,l)
  168.         diff=length(text) - length(temp_text)
  169.         first_break=lastpos(' ',temp_text,right_edge - diff)
  170.         break_point=first_break + diff
  171.         if left_edge=break_point then do
  172.             break_point=right_edge - 1
  173.             broken_word=1
  174.         end
  175.         new_text=new_text || strip(left(text,break_point),t)
  176.         if broken_word then do
  177.             new_text=new_text || '-'
  178.         end
  179.         new_text=new_text || '0a'x
  180.         text=copies(' ',left_edge) || strip(right(text,length(text) - break_point),l)
  181.     end
  182. end
  183. return new_text
  184.  
  185. /*
  186.     join -- a 'front end' for join. Fixes a problem with join.
  187.     uses a tempfile if target filename is same as one to cat
  188. */
  189. join:
  190. x=arg(1)' 'arg(2)' 'arg(3)
  191. temp='arexxtempfile'
  192. do i=1 to (words(x)-1)
  193.     if word(x,i)=word(x,words(x)) then do
  194.         oops=word(x,words(x))
  195.         x=delword(x,words(x))||'TO '||temp
  196.         address COMMAND 'Join' x
  197.         address COMMAND 'Copy 'temp' 'oops
  198.         call delete(temp)
  199.         return 0
  200.     end
  201. end
  202. x=arg(1)' 'arg(2)' TO 'arg(3)
  203. address COMMAND 'Join' x
  204. return 0
  205.  
  206. addslash:
  207. curr=arg(1)
  208. select
  209.     when right(curr, 1)=":" then nop
  210.         when right(curr, 1)="/" then nop
  211.             otherwise curr=curr"/"
  212. end
  213. return curr
  214.  
  215. /* a useful procedure by Walt Sullivan  */
  216. dequote:
  217. parse arg thing
  218. parse var thing '"' unq_thing '"'
  219. if unq_thing ~= "" then return unq_thing
  220. return thing
  221.  
  222. halt:
  223. ioerr:
  224. break_c:
  225. break_d:
  226. call writech(stdout,cr)
  227. call cleanup()
  228. exit 10
  229.  
  230. addheaders:
  231.     call writeln(STDOUT,'Appending 'areadir Number.area Name.area' to 'fileslist)
  232.     tbuf=CR||CR
  233.     tbuf=tbuf'ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸'||CR
  234.     tbuf=tbuf'³ °°°°°±±±±±²²²²²ÛÛÛÛÛ²²²²²³'center("AREA: "Number.Area,21)'³²²²²²ÛÛÛÛÛ²²²²²±±±±±°°°°° ³'||CR
  235.     tbuf=tbuf'ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´'||CR
  236.     tbuf=tbuf'³ °°°°°±±±±±²²²²²³'center(Name.Area,41)'³²²²²²±±±±±°°°°° ³'||CR
  237.     tbuf=tbuf'ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;'||CR
  238.  
  239.     if debug then call writeln(STDOUT,'Adding Area Banner to 'fileslist)
  240.     if ~open('tbl', fileslist, 'A') then do
  241.         call writeln(STDOUT,'Cannot append Area Header to 'fileslist)
  242.         signal cleanup
  243.     end
  244.     call writech('tbl',tbuf)
  245.     close('tbl');drop tbuf
  246.     if exists(areadir||areatext) then do
  247.         if debug then call writeln(STDOUT,'Adding Area description to 'fileslist)
  248.         com='Type >> "'fileslist'" "'areadir||areatext'"'
  249.         address COMMAND com
  250.     end
  251. return
  252.